package org.mespilus.mespilusweb.ui.usermanagement.client;

import org.mespilus.mespilusweb.ui.usermanagement.client.model.UserManagementModel;
import org.mespilus.mespilusweb.ui.usermanagement.client.presenter.UserDetailsPresenter;
import org.mespilus.mespilusweb.ui.usermanagement.client.presenter.UserListPresenter;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
import com.gwtext.client.core.Position;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.TabPanel;
import com.gwtext.client.widgets.form.FormPanel;
import com.gwtext.client.widgets.layout.ColumnLayout;
import com.gwtext.client.widgets.layout.ColumnLayoutData;
import com.gwtext.client.widgets.layout.FitLayout;

public class UserManagementEntry implements EntryPoint {
	protected UserManagementModel userManagementModel;
	protected UserListPresenter userListPresenter;
	protected UserListPanel userListPanel;
	protected UserDetailsPresenter userDetailsPresenter;
	protected UserDetailsPanel userDetailsPanel;
	protected GroupsPanel groupsPanel;
	
	public UserManagementEntry() {
		userManagementModel = new UserManagementModel();
		
		userListPresenter = new UserListPresenter();
		userListPanel = new UserListPanel();
		userListPanel.setPresenter(userListPresenter);
		userListPresenter.setUserListPanel(userListPanel);
		userListPanel.buildPanel();
		
		userDetailsPresenter = new UserDetailsPresenter();
		userDetailsPanel = new UserDetailsPanel();
		userDetailsPresenter.setUserDetailsPanel(userDetailsPanel);
		userDetailsPanel.setPresenter(userDetailsPresenter);
		
		
		groupsPanel = new GroupsPanel();
	}
	
	
	@Override
	public void onModuleLoad() {
		
		Panel mainPanel = new Panel();
		mainPanel.setBorder(false);
		mainPanel.setPaddings(15);
		
		FormPanel formPanel = new FormPanel();
		formPanel.setFrame(true);
		formPanel.setLabelAlign(Position.LEFT);
		formPanel.setPaddings(5);
		formPanel.setWidth(650);
		
		Panel columnOne = new Panel();
		columnOne.setLayout(new FitLayout());
		
		Panel inner = new Panel();
		inner.setLayout(new ColumnLayout());
		
		TabPanel tabPanel = new TabPanel();
		tabPanel.setActiveTab(0);
		tabPanel.setResizeTabs(true);
		tabPanel.setMinTabWidth(115);
		tabPanel.setTabWidth(200);
		tabPanel.add(userDetailsPanel.getUseDataPanel());
		tabPanel.add(groupsPanel.getUserGroupsPanel());
		
		columnOne.add(userListPanel.getUserListPanel());
		inner.add(columnOne, new ColumnLayoutData(0.6));
		
		inner.add(tabPanel, new ColumnLayoutData(0.4));
		formPanel.add(inner);
		mainPanel.add(formPanel);
		
		RootPanel.get("usermanagementId").add(mainPanel);
	}

}
